/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.transas.zornav.file;

import com.transas.zornav.data.DataSource;
import com.transas.zornav.ui.ZorNavFrame;
import java.io.BufferedWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author amalikov
 */
public class TextDataSourceWriter implements DataSourceWriter {
	private final static Logger LOG = Logger.getLogger(TextDataSourceWriter.class.getName());

	@Override
	public void process(BufferedWriter file, DataSource ds) {
		try {
			List<Object> handles = new ArrayList<Object>();
		
			List<String> names = ds.getNames();
			for (String s : names) {
				file.write(s);
				file.write('\t');
				handles.add(ds.getHandle(s));
			}
			file.newLine();
			file.newLine();

			for (int i = 0; i < ds.getSize(); ++i) {
				for (Object handle : handles) {
					file.write(ds.getValueAsString(handle, i));
					file.write('\t');
				}
				file.newLine();
			}
		} catch (IOException ex) {
			LOG.log(Level.SEVERE, null, ex);
		}
	}

}
